<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>ting Manager</title>
    <link href="/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="/">Ting</a>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li><a href="/course">课程</a></li>
                <li><a href="/upload">上传文件</a></li>
                <li class="active"><a href="/user">用户管理</a></li>
                <li><a href="/comment">评论</a></li>
            </ul>
        </div>
    </div>
</nav>
<div class="panel panel-default">
    <div class="panel-heading" style="padding-top: 0px;padding-bottom: 0px;">
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <form class="navbar-form navbar-right" action="/user" method="get">
                <div class="form-group">
                    <span style="margin-right: 10px">搜索用户:</span>
                    <input type="text" class="form-control" placeholder="用户Id" name="userId">
                </div>
                <button type="submit" class="btn btn-default">搜索</button>
            </form>
        </div>
    </div>
    <div class="panel-body">
        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
            <% for (var i = 0, user; user = users[i++];){ %>
            <div class="panel panel-default">
                <div class="panel-heading" role="tab" id="heading<%= i %>">
                    <h4 class="panel-title">
                        <a class="<%= users.length === 1 ? '' : 'collapsed' %>" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse<%= i %>"
                           aria-expanded="<%= users.length === 1 ? 'true' : 'false' %>"
                           aria-controls="collapse<%= i %>">
                            用户 :<%= user._id %>
                        </a>
                    </h4>
                </div>
                <div id="collapse<%= i %>" class="panel-collapse collapse <%= users.length === 1 ? 'in' : '' %>" role="tabpanel" aria-labelledby="heading<%= i %>">
                    <div class="panel-body">
                        <table class="table">
                            <tr>
                                <td>最后登录时间:</td>
                                <td><%= user.lastSign.toLocaleString() %></td>
                            </tr>
                            <tr>
                                <td>账号创建时间:</td>
                                <td><%= user.lastSign.toLocaleString() %></td>
                            </tr>
                            <tr>
                                <td>状态:</td>
                                <td><span class="label label-<%= user.status == '1' ? 'success' : 'danger' %>"><%= user.status == '1' ? '正常' : '禁用' %></span></td>
                            </tr>
                            <tr>
                                <td>已经订购课程:</td>
                                <td>
                                    <ul class="list-group">
                                        <% for(var j = 0, course;course = user.order[j++]; ){ %>
                                        <li class="list-group-item"><%= course %></li>
                                        <% } %>
                                        <li class="list-group-item">
                                            <form action="/user/<%= user._id %>/course" method="post">
                                                <div class="">
                                                    <div class="input-group">
                                                        <input type="text" class="form-control" placeholder="课程Id" name="courseId">
                                                        <span class="input-group-btn">
                                                            <input class="btn btn-default" type="submit">添加</input>
                                                        </span>
                                                    </div>
                                                </div>
                                            </form>
                                        </li>
                                    </ul>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <% } %>
        </div>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-heading">
        <h2 class="panel-title" style="margin-left: 20px">添加用户</h2>
    </div>
    <div class="panel-body">
        <form class="form-horizontal" method="post" action="/user">
            <div class="form-group">
                <label for="userId" class="col-sm-2 control-label">用户Id:</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input type="text" class="form-control" id="userId" name="userId" placeholder="点右侧按钮随机生成一个" aria-describedby="basic-addon2">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button" id="btn_random_userId">随机</button>
                        </span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-default">添加</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script src="/js/jquery.js"></script>
<script src="/js/bootstrap.js"></script>
<script>
    function randomString(len) {
        len = len || 32;
        var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
        /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
        var maxPos = $chars.length;
        var pwd = '';
        for (i = 0; i < len; i++) {
            pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
        }
        return pwd;
    }


    $('#btn_random_userId').click(function () {
        $('#userId').val(randomString(30))
    })
</script>
</html>